package org.dromara.system.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.api.domain.vo.RemoteDeptVo;
import org.dromara.system.api.feign.SystemDeptClient;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:23
 * @version: v1
 */
@Slf4j
@Component
public class SystemDeptFallBack implements FallbackFactory<SystemDeptClient> {

    @Override
    public SystemDeptClient create(Throwable throwable) {
        log.error("SystemDeptFallBack, cause:{}", throwable.getMessage());
        return new SystemDeptClient() {

            @Override
            public R<String> selectDeptNameByIds(String deptIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Long> selectDeptLeaderById(Long deptId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<RemoteDeptVo>> selectDeptsByList() {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Map<Long, String>> selectDeptNamesByIds(List<Long> deptIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }
        };
    }

}
